/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#include "sdk/include/logdlg.h"

#include "sdk/include/path.h"

namespace sdk
{
    BEGIN_EVENT_TABLE( LogDialog, wxDialog )
        EVT_BUTTON( wxID_CLOSE, LogDialog::OnClose )
    END_EVENT_TABLE()

    LogDialog::LogDialog( const wxString &title, const wxString &error, const wxString &details, const wxString &help )
        : wxDialog( NULL, wxID_ANY, title, wxDefaultPosition, wxSize( 420, 400 ) )
    {
        //////
        //SetIcon( wxIcon( ecPath::DirImages + wxT( "window_icon.png" ), wxBITMAP_TYPE_PNG ) );

        wxBoxSizer *bsMain = new wxBoxSizer( wxVERTICAL );
        wxBoxSizer *bsTop = new wxBoxSizer( wxHORIZONTAL );
        wxBoxSizer *bsText = new wxBoxSizer( wxVERTICAL );


    ///IMAGEN
        wxBitmap bmWarning( sdk::Path::s_dirImages + wxT("log_icon.png"), wxBITMAP_TYPE_PNG );
        wxStaticBitmap *sbmWarning = new wxStaticBitmap( this, wxID_ANY, bmWarning );

        bsTop->Add( sbmWarning, 0, wxEXPAND | wxLEFT, 10 );


    ///ERROR
        wxStaticText *stLaberDirectory = new wxStaticText( this, wxID_ANY, wxT( "Current directory:" ) );
        stLaberDirectory->SetFont( wxFont( 10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
        bsText->Add( stLaberDirectory, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );
        wxStaticText *stDirectory = new wxStaticText( this, wxID_ANY, wxGetCwd() );
        stDirectory->Wrap( 300 );
        bsText->Add( stDirectory, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );

        bsText->AddSpacer( 10 );

        wxStaticText *stLabelDate = new wxStaticText( this, wxID_ANY, wxT( "Date:" ) );
        stLabelDate->SetFont( wxFont( 10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
        bsText->Add( stLabelDate, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );
        wxStaticText *stDate = new wxStaticText( this, wxID_ANY, wxNow() );
        bsText->Add( stDate, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );

        bsText->AddSpacer( 10 );

        wxStaticText *stLabelError = new wxStaticText( this, wxID_ANY, wxT( "Error:" ) );
        stLabelError->SetFont( wxFont( 10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
        bsText->Add( stLabelError, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );
        wxStaticText *stError = new wxStaticText( this, wxID_ANY, error );
        stError->Wrap( 300 );
        bsText->Add( stError, 0, wxEXPAND | wxLEFT | wxRIGHT, 15 );

        bsTop->Add( bsText, 0, wxEXPAND | wxRIGHT | wxLEFT, 10 );





    ///INFORMATION
    //    const wxString separator( wxT( "\n\n----------------------------------------------------------------------\n\n" ) );
    //    const wxString separator( wxT( "\n\n__________________________________________________\n\n\n" ) );
        const wxString separator( wxT( "\n\n================\n\n" ) );
        const wxString message( wxT( "Details:\n" ) + details + separator + wxT( "Help:\n" ) + help );
        wxStaticBoxSizer *sbsInformation = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Information " ) );
        wxTextCtrl *txt = new wxTextCtrl( this, wxID_ANY, message, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP );
        wxTextAttr attr;
        attr.SetFont( wxFont( 10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
        txt->SetStyle( 0, 8, attr );
        int lenDetails = details.Length();
        int lenSeparator = separator.Length();
        txt->SetStyle( lenDetails+lenSeparator+9, lenDetails+lenSeparator+14, attr );
        sbsInformation->Add( txt, 1, wxEXPAND | wxALL, 5 );


        wxButton *btnClose = new wxButton( this, wxID_CLOSE, wxT( "" ) );


        bsMain->Add( bsTop, 0, wxEXPAND | wxTOP | wxBOTTOM, 20 );
        bsMain->AddSpacer( 10 );
        bsMain->Add( sbsInformation, 1, wxEXPAND | wxLEFT | wxRIGHT, 20 );
        bsMain->AddSpacer( 10 );
        bsMain->Add( btnClose, 0, wxALIGN_RIGHT | wxRIGHT, 20 );
        bsMain->AddSpacer( 10 );

        SetSizer( bsMain );
    }

    void LogDialog::OnClose( wxCommandEvent &WXUNUSED( evt ) )
    {
        EndModal( wxID_CLOSE );
    }
}
